/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * guiCadastroMusica.java
 *
 * Created on 11/06/2011, 00:32:59
 */

package guiPlaylisted.view;

import java.awt.Component;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;

/**
 *
 * @author Administrador
 */
public class guiCadastroMusica extends javax.swing.JDialog {

    private String m_cammelotWheel;
    private String m_nameArtist;
    private String m_nameTrack;
    private String m_style;

    private MusicView m_musicView;

    /** Creates new form guiCadastroMusica */
    public guiCadastroMusica(java.awt.Frame parent, boolean modal) throws FileNotFoundException, IOException, ClassNotFoundException {
        super(parent, modal);
        initComponents();

        m_musicView = MusicView.getInstance();

        this.setComboBoxes();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextNameTrack = new javax.swing.JTextField();
        jTextNameArtist = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jBtOk = new javax.swing.JButton();
        jBtCancel = new javax.swing.JButton();
        jComboStyle = new javax.swing.JComboBox();
        jComboCammelot = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(guiPlaylisted.PlaylistedApp.class).getContext().getResourceMap(guiCadastroMusica.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jTextNameTrack.setText(resourceMap.getString("jTextNameTrack.text")); // NOI18N
        jTextNameTrack.setName("jTextNameTrack"); // NOI18N
        jTextNameTrack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextNameTrackActionPerformed(evt);
            }
        });

        jTextNameArtist.setText(resourceMap.getString("jTextNameArtist.text")); // NOI18N
        jTextNameArtist.setName("jTextNameArtist"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(guiPlaylisted.PlaylistedApp.class).getContext().getActionMap(guiCadastroMusica.class, this);
        jBtOk.setAction(actionMap.get("onOK")); // NOI18N
        jBtOk.setText(resourceMap.getString("jBtOk.text")); // NOI18N
        jBtOk.setName("jBtOk"); // NOI18N

        jBtCancel.setAction(actionMap.get("onCancel")); // NOI18N
        jBtCancel.setText(resourceMap.getString("jBtCancel.text")); // NOI18N
        jBtCancel.setName("jBtCancel"); // NOI18N

        jComboStyle.setName("jComboStyle"); // NOI18N

        jComboCammelot.setName("jComboCammelot"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(146, 146, 146)
                .addComponent(jLabel5)
                .addContainerGap(139, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(75, 75, 75)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextNameTrack, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
                    .addComponent(jTextNameArtist, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jComboCammelot, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jComboStyle, javax.swing.GroupLayout.Alignment.LEADING, 0, 130, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(279, Short.MAX_VALUE)
                .addComponent(jBtOk, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jBtCancel)
                .addGap(20, 20, 20))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextNameTrack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextNameArtist, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(47, 47, 47)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jComboStyle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jComboCammelot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtOk)
                    .addComponent(jBtCancel))
                .addGap(24, 24, 24))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextNameTrackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextNameTrackActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextNameTrackActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[])  throws FileNotFoundException, ClassNotFoundException, IOException {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    guiCadastroMusica dialog = new guiCadastroMusica(new javax.swing.JFrame(), true);
                    dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                        @Override
                        public void windowClosing(java.awt.event.WindowEvent e) {
                            System.exit(0);
                        }
                    });
                    dialog.setVisible(true);
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(guiCadastroMusica.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(guiCadastroMusica.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(guiCadastroMusica.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    @Action
    public void onOK() throws FileNotFoundException, ClassNotFoundException, IOException {
        
        m_nameArtist = jTextNameArtist.getText();
        m_nameTrack = jTextNameTrack.getText();     
        m_style = (String) jComboStyle.getSelectedItem();
        m_cammelotWheel = (String) jComboCammelot.getSelectedItem();

        m_musicView.saveMusicData(m_nameTrack, m_nameArtist, m_cammelotWheel, m_style);

        this.dispose();
    }

    @Action
    public void onCancel() {
        this.dispose();
    }

    private void setComboBoxes(){
        int size_style = m_musicView.getStyles().size();
        for (int i=0; i < size_style; i++){
            jComboStyle.addItem(m_musicView.getStyles().get(i));
        }

        int size_whell = m_musicView.getWhell().size();
        for (int i=0; i < size_whell; i++){
            jComboCammelot.addItem(m_musicView.getWhell().get(i));
        }
    } 

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtCancel;
    private javax.swing.JButton jBtOk;
    private javax.swing.JComboBox jComboCammelot;
    private javax.swing.JComboBox jComboStyle;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JTextField jTextNameArtist;
    private javax.swing.JTextField jTextNameTrack;
    // End of variables declaration//GEN-END:variables

}
